import { get } from '@/utils/request'
import axios from 'axios'

export function httpApi(url) {
  const service = axios.create({
    baseURL: url.indexOf('http') !== -1 ? url : process.env.VUE_APP_BASE_API
  })
  return service.get(url)
}
export function httpPostApi(url, data) {
  const service = axios.create({
    baseURL: url.indexOf('http') !== -1 ? url : process.env.VUE_APP_BASE_API
  })
  return service.post(url, data)
}
/**
 * 获取报表查询参数
 * @param data
 * @returns {Promise<unknown>}
 */
export function getQueryInfo(data) {
  return get({
    url: '/jmreport/getQueryInfo', data
  })
}

/**
 * 获取字典值
 * @param data
 * @returns {Promise<unknown>}
 */
export function dictCodeSearch(data) {
  return get({
    url: '/jmreport/dictCodeSearch', data
  })
}

/**
 * 获取表格视图
 * @param data
 * @returns {Promise<unknown>}
 */
export function excelView(data) {
  return get({
    url: '/jmreport/show', data
  })
}

/**
 * 检查参数
 * @param reportId
 * @returns {Promise<unknown>}
 */
export function checkParam(reportId) {
  return get({
    url: '/jmreport/checkParam/' + reportId
  })
}

/**
 * 检查分享
 * @param data
 * @returns {Promise<unknown>}
 */
export function verification(data) {
  return get({
    url: '/jmreport/share/verification', data
  })
}

/**
 * 获取db信息
 * @param data
 * @returns {Promise<unknown>}
 */
export function loadTableHead(data) {
  return get({
    url: '/onlineReport/loadTableHead', data
  })
}

/**
 * 获取db信息
 * @param data
 * @returns {Promise<Response>}
 */
export function exportExcel(data) {
  const myHeaders = new Headers()
  myHeaders.append('Content-Type', 'application/json')
  const requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: data,
    redirect: 'follow'
  }
  return fetch(process.env.VUE_APP_BASE_API + '/jmreport/exportAllExcelStream', requestOptions)
}

/**
 * 获取db信息
 * @param data
 * @returns {Promise<Response>}
 */
export function exportPdf(data) {
  const myHeaders = new Headers()
  myHeaders.append('Content-Type', 'application/json')
  const requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: data,
    redirect: 'follow'
  }
  return fetch(process.env.VUE_APP_BASE_API + '/jmreport/exportPdfStream', requestOptions)
}

